package com.asion.qkan.jiguangtuisong;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.asion.qkan.db.CartoonDao;
import com.asion.qkan.db.DaoMaster;
import com.asion.qkan.db.DaoSession;
import com.asion.qkan.db.MusicDao;
import com.facebook.drawee.backends.pipeline.Fresco;

import cn.jpush.android.api.JPushInterface;

/**
 * For developer startup JPush SDK
 * 
 * 一般建议在自定义 Application 类里初始化。也可以在主 Activity 里。
 */
public class ExampleApplication extends Application {
    private static final String TAG = "JPush";
    public static Context context;

    private static SQLiteDatabase db;
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;

    @Override
    public void onCreate() {    	     
    	 Log.d(TAG, "[ExampleApplication] onCreate");
         super.onCreate();
            context = this;
         JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
         JPushInterface.init(this);     		// 初始化 JPush

        Fresco.initialize(this);
    }

    public static MusicDao getMusicDao(){
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context,"qkan_db",null);
        db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession =daoMaster.newSession();
        return daoSession.getMusicDao();
    }

    public static CartoonDao getCartoonDao(){
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context,"cartoon_db",null);
        db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession =daoMaster.newSession();
        return daoSession.getCartoonDao();
    }
}
